package crp.extensions.xjtu.sso.models;

import com.qwlabs.lang.C2;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Getter
@Setter
public class XJTUUserInfo {
    private String memberId;
    private String orgId;
    private String memberName;
    private String sex;
    private String netid;
    private List<XJTUDepartmentInfo> deptInfos;
    private List<XJTUUserType> userTypes;

    public Optional<String> getFacultyNo() {
        return C2.stream(userTypes)
                .filter(XJTUUserType::isFaculty)
                .map(XJTUUserType::getMemberNumber)
                .findFirst();
    }

    public Optional<String> getStudentNo() {
        return C2.stream(userTypes)
                .filter(XJTUUserType::isStudent)
                .map(XJTUUserType::getMemberNumber)
                .findFirst();
    }

    public List<XJTUDepartmentInfo> getDepartments(String facultyNo) {
        return C2.stream(deptInfos)
                .filter(department -> facultyNo.equals(department.getEmployeeno()))
                .collect(Collectors.toList());
    }
}
